//
//  RNOLMeClaimTransferSubViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/20.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMeClaimTransferSubViewController.h"
#import "RNOLClaimTransferCell.h"
#import "RNOLAlreadyClaimTransferCell.h"
#import "RNOLAlreadyBuyClaimTableViewCell.h"


@interface RNOLMeClaimTransferSubViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation RNOLMeClaimTransferSubViewController

- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , KHIGHT-kNavBarHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBgColor;
        adjustsScrollViewInsets_NO(_tableView, self);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , 0.01)];
        header.backgroundColor = kBgColor;
        _tableView.tableHeaderView = header;
        _tableView.tableFooterView = [UIView new];
        [_tableView registerNib:[UINib nibWithNibName: NSStringFromClass([RNOLClaimTransferCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([RNOLClaimTransferCell class])];
        [_tableView registerNib:[UINib nibWithNibName: NSStringFromClass([RNOLAlreadyClaimTransferCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([RNOLAlreadyClaimTransferCell class])];
        [_tableView registerNib:[UINib nibWithNibName: NSStringFromClass([RNOLAlreadyBuyClaimTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([RNOLAlreadyBuyClaimTableViewCell class])];
        [self.view addSubview: _tableView];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBgColor;
    [self tableView];

}

- (void)viewWillAppear:(BOOL)animated{
	[super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
	[super viewWillDisappear:animated];

}

- (void)setType:(RNOLClaimTransferType)type{
    _type = type;

}

- (NSString *)cellID{
    switch (self.type) {
        case RNOLClaimTransferTypeCanTransfer:
            return NSStringFromClass([RNOLClaimTransferCell class]);
            break;
        case RNOLClaimTransferTypeAlreadyTransfer:
            return NSStringFromClass([RNOLAlreadyClaimTransferCell class]);
            break;
        case RNOLClaimTransferTypeAlreadyBuy:
            return NSStringFromClass([RNOLAlreadyBuyClaimTableViewCell class]);
            break;
        default:
            return NSStringFromClass([RNOLClaimTransferCell class]);
            break;
     }
}

#pragma mark -  UITableViewDelegate && UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: [self cellID]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 155.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}

- (void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

#pragma mark- <SPPageSubControllerDataSource>
//子controller需要实现这个方法,如果需要cover跟着上下滑动
- (UIScrollView *)preferScrollView{
    return self.tableView;
}


@end
